package cn.com.zetatech.loader.common.enums;

import org.apache.commons.lang3.StringUtils;

import cn.com.zetatech.loader.api.exception.LoaderException;

/**
 * 数据库类型
 */
public enum DbTypeEnums {

    ORACLE("oracle"),
    STARROCKS("starrocks"),
    POSTGRESQL("postgreSql"),
    MYSQL("mysql"),
    SQLSERVER("sqlserver"),
    KUDU("kudu"),
	PostgreSQL("PostgreSQL")
    ;

    private String dbType;

    public String dbType() {
        return this.dbType;
    }

    DbTypeEnums(String dbType) {
        this.dbType = dbType;
    }
    
	public static String getDataSourceKey(String dbType) {
		if (StringUtils.isEmpty(dbType)) {
			throw new LoaderException("dbType must can't null!");
		}
		for(DbTypeEnums dbTypeEnums : DbTypeEnums.values()) {
			if(dbTypeEnums.name().equalsIgnoreCase(dbType)) {
				return dbTypeEnums.name();
			}
		}
		
		throw new LoaderException("DbTypeEnums Can't Find : " + dbType);
	}
	
	public static DbTypeEnums getDbTypeEnums(String dbType) {
		if (StringUtils.isEmpty(dbType)) {
			throw new LoaderException("dbType must can't null!");
		}
		for(DbTypeEnums dbTypeEnums : DbTypeEnums.values()) {
			if(dbTypeEnums.name().equalsIgnoreCase(dbType)) {
				return dbTypeEnums;
			}
		}
		
		throw new LoaderException("DbTypeEnums Can't Find : " + dbType);
	}

	public static void main(String[] args) {
		System.out.println(getDataSourceKey("orAcle"));
	}
}
